/**
 * Copyright(c)2012 Beijing PeaceMap Co. Ltd.
 * All right reserved.
 */
package cn.jiedh.app.meiweidk.Utils.tool;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

/**
 * activity跳转管理
 */
public class ActivityUtil {
    /**
     * 调用拨号界面
     *
     * @param phone 电话号码
     */
    public static void Phone(Context context, String phone) {
        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phone));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.getApplicationContext().startActivity(intent);
    }

    /**
     * 跳转到下一个页面
     *
     * @param //curActivity
     * @param //nextActivity
     */
    public static void next(Activity curActivity, Class<?> nextActivity) {
        Intent intent = new Intent(curActivity, nextActivity);
        curActivity.startActivity(intent);
    }

    /**
     * 跳转到下一个页面
     *
     * @param //curActivity
     * @param //nextActivity
     */
    public static void next(Context curActivity, Class<?> nextActivity) {
        Intent intent = new Intent(curActivity, nextActivity);
        curActivity.startActivity(intent);
    }

    /**
     * 跳转到下一个页面
     *
     * @param //curActivity
     * @param //nextActivity
     */
    public static void next(Activity curActivity, Class<?> nextActivity, int reqCode) {
        Intent intent = new Intent(curActivity, nextActivity);
        curActivity.startActivityForResult(intent, reqCode);
    }

    /**
     * 跳转到下一个页面,并传值
     *
     * @param //curActivity
     * @param //nextActivity
     */
    public static void next(Activity curActivity, Class<?> nextActivity, Bundle extras) {
        Intent intent = new Intent(curActivity, nextActivity);
        intent.putExtras(extras);
        curActivity.startActivity(intent);
    }

    public static void next(Context curActivity, Class<?> nextActivity, Bundle extras) {
        Intent intent = new Intent(curActivity, nextActivity);
        intent.putExtras(extras);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
        curActivity.startActivity(intent);
    }

    /**
     * 跳转到下一个页面,并传值
     *
     * @param //curActivity
     * @param //nextActivity
     */
    public static void next(Activity curActivity, Class<?> nextActivity, int reqCode, Bundle extras) {
        Intent intent = new Intent(curActivity, nextActivity);
        intent.putExtras(extras);
        curActivity.startActivityForResult(intent, reqCode);
    }

    /**
     * 跳转到下一个页面
     *
     * @param //curActivity
     * @param //nextActivity
     */
    public static void nextf(Activity curActivity, Class<?> nextActivity) {
        Intent intent = new Intent(curActivity, nextActivity);
        curActivity.startActivity(intent);
        curActivity.finish();
    }

    /**
     * 跳转到下一个页面
     *
     * @param //curActivity
     * @param //nextActivity
     */
    public static void nextf(Activity curActivity, Class<?> nextActivity, int reqCode) {
        Intent intent = new Intent(curActivity, nextActivity);
        curActivity.startActivityForResult(intent, reqCode);
        curActivity.finish();
    }

    /**
     * 跳转到下一个页面
     *
     * @param //curActivity
     * @param //nextActivity
     */
    public static void nextf(Activity curActivity, Class<?> nextActivity, Bundle extras) {
        Intent intent = new Intent(curActivity, nextActivity);
        intent.putExtras(extras);
        curActivity.startActivity(intent);
        curActivity.finish();
    }

    /**
     * 跳转到下一个页面
     *
     * @param //curActivity
     * @param //nextActivity
     */
    public static void nextf(Activity curActivity, Class<?> nextActivity, int reqCode, Bundle extras) {
        Intent intent = new Intent(curActivity, nextActivity);
        intent.putExtras(extras);
        curActivity.startActivityForResult(intent, reqCode);
        curActivity.finish();
    }


    /**
     * 返回到上一个页面
     *
     * @param //curActivity
     * @param //retCode
     */
    public static void goBack(Activity curActivity) {
        curActivity.finish();
    }

    /**
     * 返回到上一个页面
     *
     * @param //curActivity
     * @param //retCode
     */
    public static void goBack(Activity curActivity, int retCode) {
        Intent intent = null;
        intent = new Intent();
        curActivity.setResult(retCode, intent);
        curActivity.finish();
    }

    /**
     * 返回到上一个页面并返回值
     *
     * @param //curActivity
     * @param //retCode
     * @param //retData
     */
    public static void goBack(Activity curActivity, Bundle retData) {
        Intent intent = null;
        intent = new Intent();
        if (null != retData) {
            intent.putExtras(retData);
        }
        curActivity.finish();
    }

    /**
     * 返回到上一个页面并返回值
     *
     * @param //curActivity
     * @param //retCode
     * @param //retData
     */
    public static void goBack(Activity curActivity, int retCode, Bundle retData) {
        Intent intent = null;
        intent = new Intent();
        if (null != retData) {
            intent.putExtras(retData);
        }
        curActivity.setResult(retCode, intent);
        curActivity.finish();
    }


    /**
     * 直接返回到指定的某个页面
     *
     * @param //curActivity
     * @param //backActivity
     */
    public static void backActivityWithClearTop(Activity curActivity, Class<?> backActivity, Bundle extras) {
        Intent intent = new Intent(curActivity, backActivity);
       // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
        if (null != extras) {
            intent.putExtras(extras);
        }
        curActivity.startActivity(intent);
    }
}
